package com.suyuan.controller.shop.admin;


import com.suyuan.entity.OrderInfo;
import com.suyuan.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/shop/admin/Order")
public class Order2Controller {

    @Resource
    private OrderService orderService;


    /**
     * 后台展示所有订单
     * @param modelMap
     * @return
     */
    @RequestMapping("list")
    public String findAll(ModelMap modelMap){
        List<OrderInfo> orderInfoList = orderService.findAllOrder();
        modelMap.addAttribute(orderInfoList);
        return "order_list";
    }


    /**
     * 删除指定订单
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public String delete(Integer id){
        orderService.deleteOrder(id);
        return "redirect:/shop/admin/Order/list";
    }


    /**
     * 跳转编辑页面
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("toedit")
    public String toedit(Integer id,ModelMap modelMap){
        OrderInfo orderInfo = orderService.findOrderByGid(id);
        modelMap.addAttribute(orderInfo);
        return "order_edit";
    }


    @RequestMapping("edit")
    public String edit(OrderInfo orderInfo) throws Exception {
        try{
            orderService.updateOrderInfo(orderInfo);
        }catch (Exception e){
            throw new Exception("更新失败");
        }

        return "redirect:/shop/admin/Order/list";
    }





}
